package com.bayair.doctor.net.exception;

/**
 * data中的异常因为
 */
public class DataException extends RuntimeException {

    private int errCode;
    private String message;

    public DataException(int errCode) {
        this.errCode = errCode;
        initMsgByCode(errCode);
    }

    public DataException(int errCode, String msg) {
        this.errCode = errCode;
        this.message = msg;
    }


    public int getErrCode() {
        return errCode;
    }

    @Override
    public String getMessage() {
        return message;
    }

    public void setErrCode(int errCode) {
        this.errCode = errCode;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    private void initMsgByCode(int errCode) {
        if (errCode == ERROR.FREQUENTLY) {
            setMessage("发送过频繁");
        }
        if (errCode == ERROR.CHANNEL) {
            setMessage("通道错误，发送失败");
        }
        if (errCode == ERROR.VERIFICATION_CODE_ERROR) {
            setMessage("验证码错误");
        }
        if (errCode == ERROR.TOKEN_EXPIRE) {
            setMessage("token过期");
        }
        if (errCode == ERROR.VERIFICATION_CODE_NOT_RIGHT) {
            setMessage("验证码不正确");
        }
        if (errCode == ERROR.VERIFICATION_EXPIRE) {
            setMessage("验证码已过期");
        }
        if (errCode == ERROR.OTHER_ERROR) {
            setMessage("其他错误");
        }
    }

    /**
     * 约定data中异常
     */
    public static class ERROR {
        /**
         * 发送过频繁
         */
        public static final int FREQUENTLY = 100;
        /**
         * 通道错误，发送失败
         */
        public static final int CHANNEL = 101;
        /**
         * 验证码错误
         */
        public static final int VERIFICATION_CODE_ERROR = 102;
        /**
         * token过期
         */
        public static final int TOKEN_EXPIRE = 200;

        /**
         * 验证码不正确
         */
        public static final int VERIFICATION_CODE_NOT_RIGHT = 201;

        /**
         * 验证码已过期
         */
        public static final int VERIFICATION_EXPIRE = 202;

        /**
         * 其他错误
         */
        public static final int OTHER_ERROR = 999;

    }

}